package com.zlq.cn.entity;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.baomidou.mybatisplus.extension.activerecord.Model;
import com.zlq.cn.config.Config;
import com.zlq.cn.enums.UserMsgEnum;
import lombok.Data;
import lombok.EqualsAndHashCode;

import java.io.Serializable;
import java.time.LocalDateTime;

/**
 * <p>
 *
 * </p>
 *
 * @author zhoucl
 * @since 2020-12-29
 */
@Data
@EqualsAndHashCode(callSuper = false)
@TableName("z_user_msg")
public class UserMsg extends Model<UserMsg> {

    private static final long serialVersionUID = 1L;

    @TableId(value = "id", type = IdType.AUTO)
    private Integer id;

    /**
     * 消息接收者
     */
    private Integer toUserId;

    /**
     * 消息发送者；0：系统
     */
    private Integer fromUserId;

    /**
     * 消息内容
     */
    private String content;

    /**
     * 消息类型；1：好友提醒
     */
    private Integer msgType;

    /**
     * 创建时间
     */
    private LocalDateTime createTime;

    /**
     * 更新时间
     */
    private LocalDateTime updateTime;

    /**
     * 消息类标题
     */
    @TableField(exist = false)
    private String msgTitle;

    @Override
    protected Serializable pkVal() {
        return this.id;
    }

    public String buildMsgTitle() {
        for (UserMsgEnum userMsgEnum : Config.USER_MSG_ENUMS) {
            if (msgType != null && userMsgEnum.getType() == msgType) {
                return userMsgEnum.getMsgTitle();
            }
        }
        return "未知";
    }

}
